package org.electric.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

@WebFilter("/*")
public class LoginFilter extends AbstractFilter {
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		HttpServletRequest request1=(HttpServletRequest) request;
		String uri=request1.getRequestURI();
		System.out.println(uri);
		if(uri.contains("/admin-index.jsp")||uri.contains("/images/")||uri.contains("/font/")||uri.contains("/css/")||uri.contains("/js/")||uri.contains("/image/")||uri.contains("/jquery/")||uri.contains("login.jsp")||uri.contains("/index.jsp")||uri.contains("/CompanyServlet")){
		chain.doFilter(request1,response);
		}else{
			Object user=request1.getSession().getAttribute("company");
			if(user!=null){
				chain.doFilter(request, response);
				
			}else{
				request1.setAttribute("tips", "您还未登录，请先登录！");
				request.getRequestDispatcher("/login.jsp").forward(request1, response);
			}
		}
	}
}
